package com.pheruagor.handmanager.storage.impl.sqlite {
    import com.pheruagor.handmanager.assets.Member1;
    import com.pheruagor.handmanager.model.business.Member;
    import com.pheruagor.handmanager.model.business.activity.PlayerActivity;
    import com.pheruagor.handmanager.utils.TestCaseUtils;

    import flash.events.SQLEvent;

    import flexunit.framework.Assert;
    import flexunit.framework.TestCase;

    import mx.utils.UIDUtil;

    public class PlayerActivitySQLiteStorageTest extends TestCase {

        private var m_activity:PlayerActivity;
        private var m_activityStorage:PlayerActivitySQLiteStorage;

        override public function setUp():void {
            m_activity = new PlayerActivity();
            m_activityStorage = new PlayerActivitySQLiteStorage();
        }

        public function testSaveNullClub():void {
            m_activity = null;

            var onResult:Function = function(event:SQLEvent):void {
                };
            var onFault:Function = function(event:SQLEvent):void {
                };

            TestCaseUtils.assertException(function():void {
                    m_activityStorage.saveActivity(m_activity, onResult, onFault);
                }, ArgumentError);
        }

        public function testSaveEmptyClub():void {
            var onResult:Function = function(event:SQLEvent):void {
                };
            var onFault:Function = function(event:SQLEvent):void {
                };

            TestCaseUtils.assertException(function():void {
                    m_activityStorage.saveActivity(m_activity, onResult, onFault);
                }, ArgumentError);
        }

        public function testSaveActivityWhithoutId():void {
            m_activity.memberId = UIDUtil.createUID();

            var onResult:Function = function(event:SQLEvent):void {
                };
            var onFault:Function = function(event:SQLEvent):void {
                };

            TestCaseUtils.assertException(function():void {
                    m_activityStorage.saveActivity(m_activity, onResult, onFault);
                }, ArgumentError);
        }

        public function testSaveActivityWhithoutMemberId():void {
            m_activity.id = UIDUtil.createUID();
            var onResult:Function = function(event:SQLEvent):void {
                };
            var onFault:Function = function(event:SQLEvent):void {
                };

            TestCaseUtils.assertException(function():void {
                    m_activityStorage.saveActivity(m_activity, onResult, onFault);
                }, ArgumentError);
        }



        public function testSaveSimpleActivity():void {
            m_activity.id = UIDUtil.createUID();
            m_activity.memberId = UIDUtil.createUID();
            m_activity.description = "just a player";

            var onResult:Function = function(event:SQLEvent):void {
                    Assert.assertNotNull(event);
                };
            var onFault:Function = function(event:SQLEvent):void {
                };

            m_activityStorage.saveActivity(m_activity, onResult, onFault);
        }

        public function testSaveExistingClub():void {
            m_activity.id = UIDUtil.createUID();
            m_activity.memberId = UIDUtil.createUID();
            m_activity.description = "just a player";

            var onResult:Function = function(event:SQLEvent):void {
                    Assert.assertNotNull(event);
                };
            var onFault:Function = function(event:SQLEvent):void {
                };

            m_activityStorage.saveActivity(m_activity, onResult, onFault);

            m_activity.description = "just a player";
            m_activityStorage.saveActivity(m_activity, onResult, onFault);
        }

        //-----------------------------------------------------------
        // Load
        //-----------------------------------------------------------
        public function testSimpleListClubs():void {
            m_activity.id = "01";
            m_activity.memberId = "01";

            var onResult:Function = function(result:Array):void {
                    Assert.assertNotNull(result);
                };
            var onFault:Function = function(event:SQLEvent):void {
                };

            m_activityStorage.saveActivity(m_activity);
            var member:Member = new Member1();
            m_activityStorage.listActivities(member, onResult, onFault);
        }

    }
}